home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Prograph Classic 2.6.1 / Prograph Reference Manual / Prograph Reference 5-7 / Prograph Reference 5-7.rsrc / TEXT_169.txt < prev    next >
Encoding:
Text File  |  1995-10-25  |  9.3 KB  |  227 lines

  1.  
  2.  Serial Port
  3.  
  4. The Serial Port primitives allow you to send and receive ASCII data easily through the serial ports of your Macintosh. They are well-suited to the situation where you know you will only be sending ASCII data, it will be done only through the serial ports directly (never through a modem or the network), and no communications protocols (XModem, ZModem) are involved. If you need to support protocols, binary file transfers, or multiple transfer mediums, the Prograph Communications Toolbox may be more appropriate to the task.
  5.  
  6. The standard serial ports are generally on the back of the machine and are labelled with pictures of a printer and a telephone. Cards are also available that extend the serial port capabilities of the machine. You need a cable to connect the serial port to the equipment you are communicating with. Each port can be opened to receive or send data, or both.
  7.  
  8. Serial port communications can be used to interface with many kinds of instrumentation and other peripherals. If a piece of equipment can be controlled through a serial port, the manufacturer generally publishes a specification for the format of the commands or data that it understands.
  9.  
  10. Loading the Serial Port Primitives
  11.  
  12. The Serial Port primitives are stored in the Communication Primitives file.  This is located within the Disabled Primitives folder, a subfolder within the Prograph Extensions folder.  These primitives are not initially loaded with Prograph Classic, as packaged.  
  13.  
  14. NOTE:  The Communication Primitives file also contains the AppleTalk primitives.
  15. In order to use the Serial Port primitives, shut down Prograph, move the  Communication Primitives file into the Prograph Extensions folder. You may have to increase Prograph's minimum memory allocation using the Finder's Get Info dialog.  The Serial Port primitives will be available the next time you start Prograph.
  16.  
  17. Using the Serial Port Primitives
  18.  
  19. To use the primitives, first call open-serial-port for every port you intend to use; this returns a PortNum which you then pass into subsequent primitive calls that affect that port. Call configure-sport if you want configuration settings other than the defaults. Sending data is easy - just call send-serial-port. The data is sent in chunks asynchronously, so you should poll periodically with send-sport-done to see if the data have finished transmitting.
  20.  
  21. Receiving data is also done asynchronously. Use count-sport-input to see if any data has arrived on the incoming serial port, ready to read. If it is nonzero, read the data received with receive-serial-port. Sometimes it will take several calls to these two to receive all the data in the transmission.
  22.  
  23. Finally, before exiting the application, call close-serial-port for every PortNum that you opened.
  24.  
  25. Most of the Serial Port primitives return an ErrorCode. This will be 0 if the operation succeeded. There are many possible error codes that could be returned if the operation failed - see Inside Macintosh for a complete list of possibilities.
  26.  
  27. The Serial Port Primitives file must be in your Prograph Extensions folder for the primitives to becomne available in the Prograph interpreter environment.
  28.  
  29.  
  30. _________________________________________________
  31.  
  32.                                                  break-serial-port    *324*
  33.  
  34.  
  35.  
  36. Input types: integer; boolean
  37.  
  38. Output type: integer
  39.  
  40. Description: Sets the break signal on the given PortNum. If Break is TRUE, turns the break signal on. If Break is FALSE, turns the break signal off.
  41.  
  42.  
  43. _________________________________________________
  44.  
  45.                                                close-serial-port    *324*
  46.  
  47.  
  48. Input type:  integer
  49.  
  50. Output type: integer
  51.  
  52. Description: Closes the port represented by PortNum. Always call when finished with a serial port.
  53.  
  54. See also: open-serial-port
  55.  
  56.  
  57. _________________________________________________
  58.  
  59.                                           configure-sport     *325*
  60.  
  61.  
  62. Input types: integer; list
  63.  
  64. Output type:     integer
  65.  
  66. Description: Sets the configuration of the serial port PortNum. Configuration is a list of strings, consisting of one or more of the following:
  67.  
  68.  For baud rate: "baud300", "baud600", "baud1200", "baud1800", "baud2400", "baud3600", "baud4800", "baud7200", "baud9600", "baud19200" or "baud57600"
  69.  
  70.  For data bits:  "data5", "data6", "data7" or "data8"
  71.  
  72.  For parity: "evenParity", "noParity" or "oddParity"
  73.  
  74.  For stop bits: "stop10", "stop15" or "stop20"
  75.  
  76.  For CTS hardware handshaking: "CTSOn" or "CTSOff"
  77.  
  78.  For output flow control flag: "XOn" or "XOff"
  79.  
  80.  If any of the above six settings are omitted, that setting remains unchanged for the port.  The default configuration when a port is opened is ("baud9600" "data8" "noParity" "stop20" "CTSOff" "XOff").
  81.  
  82. Example: A Configuration of (‚Äúbaud2400‚Äù ‚Äúdata7‚Äù ‚ÄúoddParity‚Äù) sets the port for 2400 baud, 7 bit data and odd parity; the stop bits, CTS and XOn/XOff flags remain at whatever their current setting.
  83.  
  84. See also:  sport-configuration
  85.  
  86.  
  87. _________________________________________________
  88.  
  89.                                               count-sport-input    *325*
  90.  
  91.  
  92. Input type:     integer
  93.  
  94. Output type: integer
  95.  
  96. Description: Input size is the number of characters which are available to be read from the serial port. Use receive-serial-port to read the data.
  97.  
  98. See also:  get-sport-buffer, receive-serial-port, set-sport-buffer
  99.  
  100.  
  101. _________________________________________________
  102.  
  103.                                             get-sport-buffer    *326*
  104.  
  105.  
  106. Input types:     integer
  107.  
  108. Output type:  integer
  109.  
  110. Description: Buffer size is the size of the input buffer of the serial port.
  111.  
  112. See also:  set-sport-buffer, receive-serial-port, count-sport-input
  113.  
  114.  
  115. _________________________________________________
  116.  
  117.                                             get-sport-refs     *326*
  118.  
  119.  
  120. Input types: integer
  121.  
  122. Output types: integer; integer
  123.  
  124. Description: Returns the driver ref numbers of the output and input drivers of an open serial port.  These ref numbers are created by open-serial-port when it calls OpenDriver. An unopened driver will have a ref number of 0.
  125.  
  126.  
  127. _________________________________________________
  128.  
  129.                                              kill-serial-port    *326*
  130.  
  131.  
  132. Input types: integer; string
  133.  
  134. Output type:  integer
  135.  
  136. Description:     Kills any pending input or output (or both) on the serial port. Driver can be ‚Äúin‚Äù, ‚Äúout‚Äù or ‚Äúboth‚Äù.
  137.  
  138.  
  139. _________________________________________________
  140.  
  141.                                             open-serial-port     *327*
  142.  
  143.  
  144. Input types:  string; [string]
  145.  
  146. Output types:     integer; integer
  147.  
  148. Description: Opens a serial port and returns a PortNum. The default serial port driver names are ‚Äú.AIn‚Äù and ‚Äú.AOut‚Äù for the modem port, and ‚Äú.BIn‚Äù and ‚Äú.BOut‚Äù for the printer port. You may open a port for both input and output by passing in both driver names. Non-default driver names are usually available in documentation provided by the board's manufacturer.
  149.  
  150. See also:     close-serial-port
  151.  
  152.  
  153. _________________________________________________
  154.  
  155.                                                   receive-serial-port     *327*
  156.  
  157.  
  158. Input types: integer; integer
  159.  
  160. Output type:  string; integer
  161.  
  162. Description:  Receives Count characters from the serial port. Data is NULL if the receive operation failed. Use count-sport-input to find out how many characters are available to be read from the serial port.
  163.  
  164. See also: count-sport-input, set-sport-buffer
  165.  
  166.  
  167. _________________________________________________
  168.  
  169.                                                 send-serial-port    *327*
  170.  
  171.  
  172. Input names:     PortNum; Data; [NumTries]
  173.  
  174. Input types:  integer; string; [integer]
  175.  
  176. Defaults: NumTries = 100
  177.  
  178. Output name:  ErrorCode; [Success]
  179.  
  180. Output type: integer; [boolean]
  181.  
  182. Description: Sends the data string asynchronously to the serial port. NumTries is the number of times to try to find a free parameter block. Parameter blocks are released when data is received. Success is FALSE if all parameter blocks are in use. If no second output, operation fails instead of returning FALSE for Success. Use send-sport-done to check whether output is complete.
  183.  
  184. See also: send-sport-done
  185.  
  186.  
  187. _________________________________________________
  188.  
  189.                                             send-sport-done    *328*
  190.  
  191.  
  192. Input type:     integer
  193.  
  194. Output type:  boolean
  195.  
  196. Description: Checks whether all asynchronous output is complete. Done is TRUE if all output to the port is complete, FALSE if output is pending.
  197.  
  198. See also: send-serial-port
  199.  
  200.  
  201. _________________________________________________
  202.  
  203.                                                     set-sport-buffer    *328*
  204.  
  205.  
  206. Input types:  integer; integer
  207.  
  208. Output type:     integer
  209.  
  210. Description:  Creates a new input buffer for a serial port. If BufferSize is zero, the default buffer is used (1024 bytes). Set the buffer to a larger size to prevent the buffer filling up when you are receiving large amounts of data; if the buffer fills up, data will be lost.
  211.  
  212. See also:     count-sport-input, get-sport-buffer, receive-serial-port
  213.  
  214.  
  215. _________________________________________________
  216.  
  217.                                                    sport-configuration    *328*
  218.  
  219.  
  220. Input type:     integer
  221.  
  222. Output type: list
  223.  
  224. Description:     Configuration is a list of strings representing the current settings on the serial port. The list contains one string for each of the following settings: baud rate, stop bits, data bits, parity, XOn/XOff flow control and CTS hardware handshaking.
  225.  
  226. See also:  configure-sport
  227.